<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>加药和库存</title>
    <!--    layui-->
    <link rel="stylesheet" href="../layui-v2.6.5/layui/css/layui.css">
    <script src="../layui-v2.6.5/layui/layui.js"></script>
    <!--    自己的js-->
    <script src="../jquery/jquery-1.12.4.js"></script>
    <script src="js/drug.js" type="text/javascript"></script>

    <!--    弹出层-->
    <link rel="stylesheet" href="../layer/theme/default/layer.css">
    <script src="../layer/layer.js"></script>

    <!--    自己的样式-->
    <link rel="stylesheet" href="css/drug.css">
</head>
<body>
<!--最外层的div-->
<div>
    <!--选项卡-->
    <div class="layui-tab" lay-filter="synthesis">
        <ul class="layui-tab-title">
            <li class="layui-this">药品管理</li>
            <li lay-id='stork'>添加库存</li>
            <li>新增药品</li>
            <li>申请状态</li>
            <li></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <!-- 药品查询-->
                <div>
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">药品名称</label>
                                <div class="layui-input-inline" style="width: 160px;">
                                    <input type="text" id="drugname" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">药品类型</label>
                                <div class="layui-input-inline" style="width: 160px;">
                                    <select id="drugtype">
                                        <option value="0">查询全部</option>
                                        <option value="1">中药</option>
                                        <option value="2">西药</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table id="drug" lay-filter="drugs">

                    </table>
                </div>

            </div>

            <div class="layui-tab-item">

                <!--添加库存-->
                <div style="margin:0 auto;width:560px;">
                    <!--                    添加库存-->
                    <form action="javascript:void(0)" class="layui-form layui-form-pane store" lay-filter="test1">
                        <!--                        申请人-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请人</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <!--                        申请时间-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="date" required lay-verify="required" placeholder="请选择时间"
                                       class="layui-input" id="date"
                                       autocomplete="off">
                            </div>
                        </div>

                        <!--                        选择药品-->
                        <div class="layui-form-item">
                            <label class="layui-form-label layui-form" lay-filter="drug">选择药品</label>
                            <div class="layui-input-inline" style="width: 360px">
                                <select name="choose" lay-search required lay-verift="required">

                                </select>
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span id="sure">&nbsp;确&nbsp;定&nbsp;</span>
                            </div>
                        </div>
                        <div class="divui">
                            <ul>
                                <li class="liui">
                                    <div class="div">
                                        <span class="span">药品编号</span>
                                        <span class="span">药品名称</span>
                                        <span class="span">药品数量</span>
                                        <span class="span">操作</span>
                                    </div>
                                </li>
                            </ul>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="备注" class="layui-textarea"
                                          style="height: 140px"></textarea>
                            </div>
                        </div>

                        <!--  提交-->
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>


            </div>
            <div class="layui-tab-item">

                <!--                添加新药-->
                <div style="margin:0 auto;width:450px;">
                    <!--                    添加新药-->
                    <form action="javascript:void(0)" class="layui-form layui-form-pane add">

                        <!--                        申请人-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请人</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--                        申请时间-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="date" required lay-verify="required" placeholder="请选择时间"
                                       class="layui-input" id="date1"
                                       autocomplete="off">
                            </div>
                        </div>

                        <!--                        药品名称-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">药品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="drug" required lay-verify="required" placeholder="请输入药品名称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--                        药品类型 -->
                        <div class="layui-form-item">
                            <label class="layui-form-label">药品类型</label>
                            <div class="layui-input-block" lay-filter="drug">
                                <select name="type" lay-search>
                                    <option value="1">中药</option>
                                    <option value="2">西药</option>
                                </select>
                            </div>
                        </div>

                        <!--                        单价 -->
                        <div class="layui-form-item">
                            <label class="layui-form-label">药品价格</label>
                            <div class="layui-input-block">
                                <input type="text" name="price" required lay-verify="required|number"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--                        数量 -->
                        <div class="layui-form-item">
                            <label class="layui-form-label">药品数量</label>
                            <div class="layui-input-block">
                                <input type="text" name="count" required lay-verify="required|number"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--                        备注-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="备注" class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <!--                        提交-->
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
            <div class="layui-tab-item">
                <!--                查看申请状态-->
                <div>
                    <!--                    条件查询-->
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">查询时间</label>
                                <div class="layui-input-inline" style="width: 160px;">
                                    <select id="time">
                                        <option value="0">查询全部</option>
                                        <option value="1">最近一周</option>
                                        <option value="2">最近一月</option>
                                        <option value="3">最近一年</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">申请类型</label>
                                <div class="layui-input-inline" style="width: 160px;">
                                    <select id="type">
                                        <option value="0">查询全部</option>
                                        <option value="1">补充库存</option>
                                        <option value="2">增加新药</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>

                    <table id="demo" lay-filter="show">

                    </table>

                </div>

            </div>
            <div class="layui-tab-item"></div>
        </div>
    </div>
</div>

</body>

<!--药品管理头工具栏事件-->
<script type="text/html" id="toolbarDemo2">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="sel">查询</button>
        <button class="layui-btn layui-btn-sm" lay-event="upd">刷新</button>
        <button class="layui-btn layui-btn-sm" lay-event="check">检查库存</button>
    </div>
</script>

<!--申请状态头工具栏事件-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="sel">查询</button>
        <button class="layui-btn layui-btn-sm" lay-event="upd">刷新</button>
    </div>
</script>

<!--申请状态行工具栏-->
<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="add">入库</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!--药品管理行工具栏-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="decl">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!--layui模块-->
<script>
    //tab切换
    layui.use('element', function () {
        let element = layui.element;
    });
    //加载时间控件
    layui.use('laydate', function () {
        let date = layui.laydate;
        //执行一个date实例
        date.render({
            elem: '#date',  //指定元素
            type: "datetime",
            format: "yyyy年MM月dd日 HH时mm分ss秒",
            theme: "blue"
        });
    });
    //加载时间控件
    layui.use('laydate', function () {
        let date = layui.laydate;
        //执行一个date实例
        date.render({
            elem: '#date1',  //指定元素
            type: "datetime",
            format: "yyyy年MM月dd日 HH时mm分ss秒",
            theme: "blue"
        });
    });
    //加载表格
    layui.use('table', function () {
        let table = layui.table;
        //加载实例
        table.render({
            elem: "#demo",        //指定元素
            id: "demo",            //表标识
            toolbar: "#toolbarDemo",  //表头工具栏
            height: 300,            //宽度
            url: "http://localhost:8080/com/initServlet?opr=applyInit",              //数据接口
            method: "post",       //添加类型
            page: true,           //开启分页
            limit: 10,            //每页显示的条数
            cols: [[              //表头
                {field: 'id', title: '编号', width: 100, sort: true, fixed: 'left'}
                , {field: 'name', title: '申请人', width: 100}
                , {
                    field: 'date', title: '申请时间', width: 160, sort: true, templet(d) {
                        return layui.util.toDateString(d.date, "yyyy-MM-dd HH:mm:ss")
                    }
                }
                , {field: 'type', title: '申请类型', width: 100}
                , {
                    field: 'applyStatus', title: '申请状态', width: 100, templet: function (d) {
                        return d.applyStatus === 0 ? "<span style='color: #e72727'>审核未通过</span>" : "<span style='color: #35f535'>审核通过</span>"
                    }
                }
                , {
                    field: 'drugSpecies', title: '库存药品数量', width: 120, templet(d) {
                        return d.drugSpecies === 0 ? "" : d.drugSpecies
                    }
                }
                , {field: 'applyDrug', title: '新增药品名称', width: 120}
                , {
                    field: 'drugType', title: '新增药品类型', width: 120, templet: function (d) {
                        if (d.drugType === 0) {
                            return '';
                        }
                        return d.drugType === 1 ? '中药' : '西药'
                    }
                }
                , {field: 'price', title: '新增药品单价', width: 140, sort: true}
                , {field: 'count', title: '药品数量', width: 120, sort: true}
                , {field: 'remark', title: '备注', width: 160}
                , {field: 'tool', title: '操作', width: 180, toolbar: "#barDemo2", fixed: 'right'}    //行工具栏
            ]],
            //默认文本
            text: {
                none: '暂无数据'
            },
            //条件
            where: {
                date: '0',     //用户选择时间
                type: '0'      //用户的操作类型
            }
        })
        //监听事件  其中 show 参数为标识  lay-filter="show"
        table.on('toolbar(show)', function (obj) {
            //拿到当前的容器  拿到id即拿到该容器  通过id就可以做很多事情  例如返回当前被选择的数据
            let demo = table.checkStatus(obj.config.id);
            // obj.event 可以拿到当前的事件名
            let date = $("#time").val();     //用户选择
            let type = $("#type").val();     //申请类型
            switch (obj.event) {
                case 'sel':
                    table.reload('demo', {
                        page: {
                            curr: 1    //起始页
                        },
                        where: {       //传递的参数
                            date: date,   //用户选择的查询时间端
                            type: type    //申请类型
                        }
                    })
                    break;
                case 'upd':
                    table.reload('demo', {
                        where: {          //传递的参数
                            date: date,   //用户选择的查询时间端
                            type: type    //申请类型
                        }
                    })
                    break;
            }
        });

        let flag = false;    //标记
        //行工具条
        table.on('tool(show)', function (obj) {
            let choo = obj.event;    //拿到事件名
            if (flag) {
                return;
            }
            flag = true;
            switch (choo) {
                case 'add':
                    if (obj.data.applyStatus !== 1) {
                        layer.msg("只有申请通过才能入库")
                        flag = !flag;
                        return;
                    }
                    $.ajax({
                        url: "http://localhost:8080/com/drugServlettt",
                        type: "post",
                        data: {
                            opr: 'drugManage',
                            id: obj.data.id,
                            name: obj.data.name,
                            dates: obj.data.date,
                            drugName: obj.data.applyDrug,
                            drugType: obj.data.drugType,
                            price: obj.data.price,
                            count: obj.data.count,
                            types: obj.data.type,
                            remark: obj.data.remark
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data === 0) {
                                layer.msg("添加库存失败")
                            } else if (data === 1) {
                                layer.msg("添加库存成功")
                            } else if (data === 2) {
                                layer.msg("新增药品成功")
                            }
                            let date = $("#time").val();     //用户选择
                            let type = $("#type").val();     //申请类型
                            //刷新
                            table.reload('demo', {
                                where: {          //传递的参数
                                    date: date,   //用户选择的查询时间端
                                    type: type    //申请类型
                                }
                            });
                            flag = !flag;
                        }
                    });
                    break;
                case 'edit':
                    if (obj.data.type === "新增药品") {
                        flag = !flag;
                        return;
                    }
                    $.ajax({
                        url: "http://localhost:8080/com/initServlet",
                        type: "post",
                        data: {
                            opr: 'selStork',
                            date: obj.data.date
                        },
                        dataType: "json",
                        success: function (data) {
                            let lis = ``;
                            let zj = 0;
                            for (let i = 0; i < data.length; i++) {
                                let money = parseInt(data[i].price) * parseInt(data[i].count);
                                zj += money;
                                lis += `<li class="liui2">
                                           <span class="span2">${data[i].drugName}</span>
                                           <span class="span2">${data[i].price}</span>
                                           <span class="span2">${data[i].count}</span>
                                           <span class="span2">${money}</span>
                                        </li>`;
                            }
                            let div = `<div>
                                         <ul>
                                           <li class="liui">
                                             <span class="span">药品名称</span>
                                             <span class="span">药品价格</span>
                                             <span class="span">药品数量</span>
                                             <span class="span">金额小计</span>
                                           </li>
                                           ${lis}
                                           <li class="liui">
                                             <span class="span"></span>
                                             <span class="span"></span>
                                             <span class="span">药品总价</span>
                                             <span class="span">${zj}</span>
                                           </li>
                                         </ul>
                                       </div>`;
                            layer.open({
                                id: "one",    //设定id
                                title: "<span class='test'>库存药品名单</span>",   //标题
                                type: 1,                  //弹出层类型
                                content: div,             //弹出内容
                                skin: 'test',             //皮肤
                                area: 'auto',             //宽高
                                offset: ['150px', '500px'],     //X轴 Y轴
                                btn: ['关闭全部'],         //关闭按钮
                                bthAlign: 'c',            //关闭按钮位置
                                closeBth: 1,              //关闭按钮样式
                                shade: 0                  //外阴影
                            })
                            flag = !flag;
                        }
                    })
                    break;
                case 'del':
                    layer.msg('没有权限')
                    flag = !flag
                    break;
            }
        })
    })

    //标记
    let flag = false;
    //加载表格
    layui.use('table', function () {
        let table = layui.table;
        table.render({
            elem: '#drug',
            id: "drug",
            height: 520,
            url: "http://localhost:8080/com/initServlet?opr=drugQuery",
            method: 'post',
            page: true,
            limit: 10,
            toolbar: "#toolbarDemo2",  //表头工具栏
            cols: [[
                {field: 'id', title: '药品编号', width: 140, sort: true, fixed: 'left'},
                {field: 'drugName', title: '药品名称', width: 120},
                {
                    field: 'type', title: '药品类型', width: 140, templet: function (d) {
                        return d.type === 1 ? '中药' : '西药';
                    }
                },
                {field: 'price', title: '药品价格', width: 120, sort: true, edit: 'text'},
                {
                    field: 'count', title: '库存数量', width: 120, sort: true, templet: function (d) {
                        return d.count;
                    }
                },
                {field: 'remark', title: '药品描述', width: 400, edit: 'text'},
                {
                    field: 'show', title: '库存状态', width: 100, templet: function (d) {
                        return d.count < 100 ? "<span style='color: #e72727'>库存不足</span>" : "<span style='color:#35f535'>库存充足</span>"
                    }
                },

                {field: 'tool', title: '操作', width: 140, toolbar: "#barDemo"}
            ]],
            text: {
                none: '暂无数据'
            },
            where: {
                drugName: "",    //药品名称
                drugType: 0          //药品类型
            },
            done: function (res) {
                if (flag) {
                    return;
                }
                let data = res.data;
                if (data.length === 0) {
                    return;
                }
                flag = true;
                //查询库存状态
                $.ajax({
                    url: "http://localhost:8080/com/initServlet",
                    type: "post",
                    data: {
                        opr: "check"
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.length <= 0) {
                            return;
                        }
                        let lis = ``;     //数据集合
                        for (let i = 0; i < data.length; i++) {
                            if (data[i].count < 100) {
                                lis += `<li class="liuis">
                                        <input type="checkbox" class="check">
                                        <span class="span">${data[i].id}</span>
                                        <span class="span">${data[i].drugName}</span>
                                        <span class="span">${data[i].count}</span>
                                        </li>`
                            }
                        }
                        let div = `<div class="kun">
                                      <h2 class="title">库存名单</h2>
                                      <div>
                                          <ul>
                                            <li class="liui">
                                                <input type="checkbox" class="check">
                                                <span class="span">药品编号</span>
                                                <span class="span">药品名称</span>
                                                <span class="span">剩余库存</span>
                                            </li>
                                            ${lis}
                                          </ul>
                                      </div>
                                   </div>`;
                        //弹出层
                        layer.open({
                            id: 'hint',                //设定一个id，防止重复弹出
                            type: 1,                   //弹出层类型
                            title: false,              //不显示标题栏
                            content: div,              //弹出层内容
                            closeBtn: false,           //关闭按钮
                            resize: false,             //是否允许窗口拉伸
                            btn: ['申请入库', '全部关闭'],      //按钮
                            btnAlign: 'c',             //按钮居中
                            moveType: 1,               //拖拽模式，0或者1
                            yes: function (index, layero) {
                                //创建药单
                                let len = $("body .kun .liuis").find(".check:checked").length;
                                //判断复选框选择的数量如果为0就跳过
                                if (len === 0) {
                                    layer.close(index);
                                    return;
                                }
                                // 重新加载模块
                                layui.use('element', function () {
                                    let element = layui.element;
                                    element.tabChange('synthesis', 'stork');
                                });
                                let drugNames = "";
                                $("body .kun .liuis").find(".check:checked").each(function () {
                                    let drugID = $(this).next().text();
                                    let drugName = $(this).next().next().text();
                                    drugNames += " " + drugName + " ";
                                    let li = `<li class="liui2">
                                          <div class="div2">
                                            <span class="span2">${drugID}</span>
                                            <span class="span2">${drugName}</span>
                                            <span class="span2">
                                                <input type="text" class="input">
                                            </span>
                                            <span class="span2">
                                                <a href="javascript:void(0)">删除</a>
                                            </span>
                                          </div>
                                      </li>`;
                                    $(".divui>ul").append(li);
                                })
                                //关闭弹出层
                                layer.close(index);
                                $.ajax({
                                    url: "http://localhost:8080/com/initServlet",
                                    type: "post",
                                    data: {
                                        opr: "massage",
                                        drugNames: drugNames
                                    },
                                    dataType: "json",
                                    success: function (data) {

                                    }
                                })
                            },
                            btn2: function (index, layero) {
                                layer.close(index);
                            }
                        })
                    }
                })
            }
        })
        //工具头  做了查询和刷新
        table.on('toolbar(drugs)', function (obj) {
            let drugs = table.checkStatus(obj.config.id);
            let drugName = $("#drugname").val();
            let drugType = $("#drugtype").val();
            switch (obj.event) {
                case 'sel':
                    table.reload('drug', {
                        page: {
                            curr: 1
                        },
                        where: {
                            drugName: drugName,
                            drugType: drugType
                        }
                    })
                    break;
                case 'upd':
                    table.reload('drug', {
                        where: {
                            drugName: drugName,
                            drugType: drugType
                        }
                    })
                    break;
                case 'check':
                    //查询库存状态
                    $.ajax({
                        url: "http://localhost:8080/com/initServlet",
                        type: "post",
                        data: {
                            opr: "check"
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.length === 0) {
                                layer.msg("当前库存充足")
                                return;
                            }
                            let lis = ``;     //数据集合
                            for (let i = 0; i < data.length; i++) {
                                if (data[i].count < 100) {
                                    lis += `<li class="liuis">
                                        <input type="checkbox" class="check">
                                        <span class="span">${data[i].id}</span>
                                        <span class="span">${data[i].drugName}</span>
                                        <span class="span">${data[i].count}</span>
                                        </li>`
                                }
                            }
                            let div = `<div class="kun">
                                      <h2 class="title">库存名单</h2>
                                      <div>
                                          <ul>
                                            <li class="liui">
                                                <input type="checkbox" class="check">
                                                <span class="span">药品编号</span>
                                                <span class="span">药品名称</span>
                                                <span class="span">剩余库存</span>
                                            </li>
                                            ${lis}
                                          </ul>
                                      </div>
                                   </div>`;
                            //弹出层
                            layer.open({
                                id: 'hint2',                //设定一个id，防止重复弹出
                                type: 1,                   //弹出层类型
                                title: false,              //不显示标题栏
                                content: div,              //弹出层内容
                                closeBtn: false,           //关闭按钮
                                resize: false,             //是否允许窗口拉伸
                                btn: ['申请入库', '全部关闭'],      //按钮
                                btnAlign: 'c',             //按钮居中
                                moveType: 1,               //拖拽模式，0或者1
                                yes: function (index, layero) {
                                    let len = $("body .kun .liuis").find(".check:checked").length;
                                    //判断复选框选择的数量如果为0就跳过
                                    if (len === 0) {
                                        //关闭弹出层
                                        layer.close(index);
                                        return;
                                    }
                                    // 重新加载模块
                                    layui.use('element', function () {
                                        let element = layui.element;
                                        element.tabChange('synthesis', 'stork');
                                    });
                                    let drugNames = "";
                                    //创建药单
                                    $("body .kun .liuis").find(".check:checked").each(function () {
                                        let drugID = $(this).next().text();
                                        let drugName = $(this).next().next().text();
                                        drugNames += " " + drugName + " ";
                                        let li = `<li class="liui2">
                                          <div class="div2">
                                            <span class="span2">${drugID}</span>
                                            <span class="span2">${drugName}</span>
                                            <span class="span2">
                                                <input type="text" class="input">
                                            </span>
                                            <span class="span2">
                                                <a href="javascript:void(0)">删除</a>
                                            </span>
                                          </div>
                                      </li>`;
                                        $(".divui>ul").append(li);
                                    })
                                    //关闭弹出层
                                    layer.close(index);
                                    $.ajax({
                                        url: "http://localhost:8080/com/initServlet",
                                        type: "post",
                                        data: {
                                            opr: "massage",
                                            drugNames: drugNames
                                        },
                                        dataType: "json",
                                        success: function (data) {

                                        }
                                    })
                                },
                                btn2: function (index, layero) {
                                    layer.close(index);
                                }
                            })
                        }
                    })
                    break;
            }
        })

        //单元格编辑  单独更改字段
        table.on('edit(drugs)', function (obj) {
            $.ajax({
                url: "http://localhost:8080/com/drugServlettt",
                type: "post",
                data: {
                    opr: "upDrug",    //操作符
                    id: obj.data.id,    //药品编号
                    field: obj.field,   //字段名
                    value: obj.value     //属性值
                },
                dataType: 'json',
                success: function (data) {

                }
            })
        })

        //行工具条
        table.on('tool(drugs)', function (obj) {
            let choo = obj.event;    //拿到事件名
            let date = obj.data;
            switch (choo) {
                case 'decl':
                    layer.prompt({
                        formType: 2,
                        title: '药品描述',
                        value: date.remark
                    }, function (value, index) {
                        $.ajax({
                            url: "http://localhost:8080/com/drugServlettt",
                            type: "post",
                            data: {
                                opr: "upRemark",    //操作符
                                id: date.id,    //药品编号
                                value: value
                            },
                            dataType: 'json',
                            success: function (data) {

                            }
                        })
                        obj.update({
                            remark: value
                        })
                        layer.close(index);
                    })
                    break;
                case 'del':
                    layer.msg('删除药品请与相关人员联系')
                    break;
            }
        })
    })
    //加载表单
    layui.use('form', function () {
        let form = layui.form;
        form.render('select', 'test1');
    });
</script>

</html>